/* 
 *  Copyright (c) 2011—2013 Panguso.com. All rights reserved. 
 *  File Name:  ReadStatisticsServiceImpl.java                                      
 *  File Contents Outline :  统计信息读取
 *  File  Create Date:   2012年7月30日
 *  File Version#: Revision#: #1                  
 *  File  Latest Modify Date : 2013年1月16日
 *  File Author :  bachuan@panguso.com
 */
package cn.edu.thu.log.web.service.impl;

import cn.edu.thu.log.web.service.ReadStatisticsService;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;

public class ReadStatisticsServiceImpl implements ReadStatisticsService {

    private static ReadStatisticsService singleton = null;
    private ArrayList<String> list; 
            
    public synchronized static ReadStatisticsService instance() {
        if (singleton == null) {
            singleton = new ReadStatisticsServiceImpl();
        }
        return singleton;
    }

    @Override
    public ArrayList<String> readStatisticsFile(String filename) {
        list=new ArrayList<String>();
        File file = new File(filename);
        BufferedReader reader = null;
        try {       
            reader = new BufferedReader(new FileReader(file));
            String tempString = null;
//            int line = 1;
            // 一次读入一行，直到读入null为文件结束
            while ((tempString = reader.readLine()) != null) {
                // 显示行号
//               System.out.println("line " + line + ": " + tempString);
//                line++;
                list.add(tempString);
            }
            reader.close();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (reader != null) {
                try {
                    reader.close();
                } 
                catch (IOException e1) {
                }
            }
        }
        return list;
    }
}
